//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================

//====================================================
// Created     : 2004-1-6
// Author      : FengTao
// Description : Some test functions for Bsp and a part
//               of core
//====================================================

#include <core.h>
#include "kernelentry1.h"

EXTERN_C DECL_CODEINIT void CDECL TestKernelInitialize1()
{
    kprintf("******FUNCTION_BSP_FENGTAO\n");

    TestDescriptor1();
    Testx86();

    kprintf("******FUNCTION_BSP_FENGTAO_END\n");
}

EXTERN_C DECL_CODEINIT void CDECL TestKernelStartup1()
{
    kprintf("******FUNCTION_CORE_FENGTAO\n");

    TestInterrupt1();
//    TestPhysMem1();
    TestThread1();

    kprintf("******FUNCTION_CORE_FENGTAO_END\n");
}

//EXTERN_C void CDECL TestPhysMem1()
//{
//    kprintf("======\n");
//    uint32_t uNumOfFreePages = 0;
//    for(uint_t i = 0; i < 5; i++) {//buddylist is not shown
//        kprintf("g_zones[%d].mregion.uBasePageNo is %d\n", i,
//                g_zones[i].m_region.uBasePageNo);
//        kprintf("g_zones[%d].mregion.uLimitPageNo is %d\n", i,
//                g_zones[i].m_region.uLimitPageNo);
//        kprintf("g_zones[%d].m_nApproxMaxOrder is %d\n", i,
//                g_zones[i].m_nApproxMaxOrder);
//        kprintf("g_zones[%d].m_uNumberOfFreePages is %d\n", i,
//                g_zones[i].m_uNumberOfFreePages);
//        uNumOfFreePages += g_zones[i].m_uNumberOfFreePages;
//    }
//    kprintf("NumberOfFreePages is %d\n", GetNumberOfFreePages());
//    if (uNumOfFreePages != GetNumberOfFreePages())
//        kprintf("ERROR NumOfFreePages\n");
//}

EXTERN_C void CDECL TestThread1()
{
    kprintf("======\n");
    Thread *pThread = NULL;
    pThread = GetThread0();
    kprintf("Address of Thread0 is %x\n", pThread);
    if (pThread->IsRunning())
        kprintf("state of Thread0 is Running!\n");
    else
        kprintf("state of Thread0 is Zombie!\n");
    kprintf("Thread0.bNeedReschedule is %d\n", pThread->m_bNeedReschedule);
    pThread = GetCurrentThread();
    kprintf("Address of CurrentThread is %x\n", pThread);
    if (pThread->IsRunning())
        kprintf("state of CurrentKernelThread is Running!\n");
    else
        kprintf("state of CurrentKernelThread is Zombie!\n");
    kprintf("CurrentKernelThread.bNeedReschedule is %d\n",
            pThread->m_bNeedReschedule);
}
